package com.itboye.sunsun.adapter;

import java.util.Iterator;
import java.util.List;

import com.itboye.sunsun.beans.OrderBean.InnerDetailBean;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.network.HttpRequest;
import com.itboye.sunsun.utils.SPUtils;
import com.itboye.sunsun.volley.MyJsonRequest;
import com.itboye.sunsun.volley.XErrorListener;
import com.itboye.sunsun.volley.XRequestListener;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

public class AllOrderAdapter extends AbstractOrderAdapter {

	public AllOrderAdapter(Context context, List<InnerDetailBean> list) {
		super(context, list);
	}

	@Override
	public String onGetLeftTextviewText() {
		return "取消订单";
	}

	@Override
	public String onGetRightTextviewText() {
		return "付款";
	}

	@Override
	public void onLeftViewClick(View v) {
		deleteorder((String)v.getTag());
	} 

	@Override
	public void onRightViewClick(View v) {

	}

	
	private void deleteorder(final String s){
		MyJsonRequest<String>request=new MyJsonRequest.Builder<String>()
				.typeKey("BY_Orders_qxorder")
				.apiVer("100")
				.param("order_code", s)
				.param("uid", (String)SPUtils.get(context, null, SPContants.USER_ID	, ""))
				.requestListener(new XRequestListener<String>() {
					@Override
					public void onResponse(String arg0) {
						 
						Toast.makeText(context, arg0, 1).show();
						Iterator<InnerDetailBean> itr=list.iterator();
						while ( itr.hasNext()) {
							if (s.equals(itr.next().getOrderCode())) {
								itr.remove();
							}
						}
						
						notifyDataSetChanged();
					}
				})
				.errorListener(new XErrorListener() {
					
					@Override
					public void onErrorResponse(Exception exception, int code, String msg) {
						 
						
					}
				})
				.build();
		
		HttpRequest.getDefaultRequestQueue().add(request);
	}
	
}
